﻿jQuery.httpRootPath = function() {
  // return "http://218.64.54.43:8086/arsapp-jx";
  return "http://" + window.location.host + "/arsapp-jx";
};


/**
 * 获取URL中含有目标参数（name）的值
 * @param name
 * @returns {null}
 */
function getUrlParam(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg); //匹配目标参数
  if (r != null) return unescape(r[2]);
  return null; //返回参数值
}


/**
 * 获取cookie
 * @param name
 */
function getCookie(name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(name + "=")
    if (c_start != -1) {
      c_start = c_start + name.length + 1
      c_end = document.cookie.indexOf(";", c_start)
      if (c_end == -1) c_end = document.cookie.length
      return unescape(document.cookie.substring(c_start, c_end))
    }
  }
  return ""
}

/**
 * 设置cookie
 * @param name
 */
function setCookie(name, value, expiredays) {
  var exdate = new Date()
  exdate.setDate(exdate.getDate() + expiredays)
  document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString())
}


/* *****************
 *
 * name：需要变化的class或者id
 * h1：动画开始前的初始值
 * h2：动画变化距离的大小
 * h_until：关闭动画的条件
 * speed：速度 
 * up：true:往上,false:往下，默认false。
 *
 * *****************/
function transformAnimation(name, h1, h2, h_until, speed, up) {
  console.log("开始css3动画");
  up = up || false;

  var r = setInterval(function() {
    if (up) {
      if (h1 > h_until) {
        transformCss(name, h1);
        h1 = h1 - h2;
      } else {
        clearInterval(r);
        transformCss(name, h_until);
      }
    } else {

      if (h1 > h_until) {
        clearInterval(r);
        transformCss(name, h_until);
      } else {
        transformCss(name, h1);
        h1 = h1 + h2;
      }
    }


  }, speed);
}


/* *****************
 *
 * name：需要设置css的的class或者id名
 * h：值
 *
 * *****************/
function transformCss(name, h) {
  $(name).css({
    "-webkit-transform": " translateY(" + h + "px)",
    "-moz-transform": " translateY(" + h + "px)",
    "-ms-transform": " translateY(" + h + "px)",
    "-o-transform": " translateY(" + h + "px)",
    "transform": " translateY(" + h + "px)"
  });
}


/* *****************
 *
 * name：需要获得TranslateY值的css的的class或者id名
 *
 * *****************/
function getTranslateY(name) {
  var h;
  h = $(name).css("transform") || $(name).css("-webkit-transform") || $(name).css("-moz-transform") || $(name).css("-ms-transform") || $(name).css("-o-transform");

  if (!h) {
    return false;
  }
  h = h.replace(/[^0-9\.\-,]/g, '').split(',');
  h = h[h.length - 1]
  h = parseFloat(h);
  return h;
}

/**
 * [isMobile 判断平台]
 * @param test: 0:iPhone    1:Android
 */
function ismobile(test){
    var u = navigator.userAgent, app = navigator.appVersion;
    if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
     if(window.location.href.indexOf("?mobile")<0){
      try{
       if(/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)){
        return '0';
       }else{
        return '1';
       }
      }catch(e){}
     }
    }else if( u.indexOf('iPad') > -1){
    return '0';
    }else{
    return '1';
    }
};
  
  
  